<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.scalar.chiptrack.utils.ConfigManager"%>
<%@ page import="com.scalar.chiptrack.users.Functionality" %>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext(); %>

<html>
<HEAD>
<TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>
<SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></SCRIPT>
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>
<script language="javascript">
var dateElement = "";
    function openCalendar(dateValue)
    {
        if ( dateValue.disabled )
        {
            return;
        }
        dateElement = dateValue;
        newWindow = window.open('<%=chipTracContext%>/jsp/includes/calendar.html','calenderPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=180,height=440,resizable=no');
        newWindow.moveTo(550,180);
        newWindow.focus();
    }

    function assignDate(passedValue)
    {
        dateElement.value=passedValue;
        window.focus();
    }
    function submitForm()
    {
        var form = document.directMarginReportForm;
        if ( validateForm() )
        {
            form.action = "<%=chipTracContext%>/directMarginReport.do?action=loadDirectMargins"
            form.submit();
        }
    }
    function validateForm()
    {
        var form = document.directMarginReportForm;
        var pa = document.getElementById( "errors" );
        pa.innerHTML = "";
        var dmpCtrl =  form.searchDMPercentage;
        var searchFromDateCtrl = form.searchFromDate;
        var searchToDateCtrl = form.searchToDate;
        if ( checkFloat ( dmpCtrl.value,' DM% ','N'  ) == false )
        {
            pa.innerHTML = "<li> "+errMsg+" or characters";
            dmpCtrl.focus();
            dmpCtrl.select();
            return false;
        }
        if(chkDate(searchFromDateCtrl.value,'From-Date','N') == false)
        {
            pa.innerHTML = errMsg;
            searchFromDateCtrl.focus();
            return false;
        }

        if(chkDate(searchToDateCtrl.value,'To-Date','N') == false)
        {
            pa.innerHTML = errMsg;
            searchToDateCtrl.focus();
            return false;
        }

        if(searchFromDateCtrl.value!='' && searchToDateCtrl.value!='')
        {
            if (!validateDateOut(formatDateAsMMDDYYYY(searchFromDateCtrl.value),formatDateAsMMDDYYYY(searchToDateCtrl.value)))
            {
                pa.innerHTML = "<li>To Date cannot be less than From Date";
                searchToDateCtrl.focus();
                return false;
            }
        }
        return true;
    }
    function enableDisableDateFields()
    {
        var form = document.directMarginReportForm;
        var searchStatusValue = form.searchStatus.value;
        var searchDateTypes = form.searchDateType;
        var searchFromDateCtrl = form.searchFromDate;
        var searchToDateCtrl = form.searchToDate;
        if ( searchStatusValue == 'Backlog' )
        {
            //disable all
            for ( var k=0; k < searchDateTypes.length; k++ )
            {
                searchDateTypes[k].disabled = true;
            }
            searchFromDateCtrl.disabled = true;
            searchToDateCtrl.disabled = true;
        }
        else if ( searchStatusValue == 'Backlog_Shipment' || searchStatusValue == 'Shipment' )
        {
            //enable all
            //ship date default selected
            for ( var k=0; k < searchDateTypes.length; k++ )
            {
                searchDateTypes[k].disabled = false;
                if ( searchDateTypes[k].value == 'shipment' )
                {
                    searchDateTypes[k].checked = true;
                }
            }
            searchFromDateCtrl.disabled = false;
            searchToDateCtrl.disabled = false;
        }
        else
        {
            //enable all
            //booking default selected
            for ( var k=0; k < searchDateTypes.length; k++ )
            {
                searchDateTypes[k].disabled = false;
                if ( searchDateTypes[k].value == 'booking' )
                {
                    searchDateTypes[k].checked = true;
                }
            }
            searchFromDateCtrl.disabled = false;
            searchToDateCtrl.disabled = false;
        }
    }
    function resetForm()
    {
        var form = document.directMarginReportForm;
        form.reset();
        enableDisableDateFields();
    }
</script>
</HEAD>

<BODY bgColor="#ffffff" leftMargin=0 topMargin=0 marginheight="0" marginwidth="0" onload="enableDisableDateFields()">
<!-- Top Header Start-->
<%@include file="/jsp/includes/header.jsp"  %>
<!-- Top Header End-->
<table cellSpacing=0 cellPadding=0 width="100%" border=0>
    <tr>
	    <td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
            <!-- Side Navigation start -->
            <%@ include file="/jsp/finance/finance_reports_menu.jsp" %>
            <!-- end of the side navigations -->
        </td>
        <td bgcolor="#ffffff"><IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></td>
        <td bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></td>
        <td valign="top" width="100%">
            <img height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
            <!-- Start : Wip Flush -->
            <html:form action="/directMarginReport.do" name="directMarginReportForm" type="com.scalar.chiptrack.finance.reports.forms.DirectMarginReportForm">
            <table width="100%" border="0">
                <tr>
                    <td valign="top" bgcolor="#ffffff" width="10%">
                        <img height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width="2">
                    </td>
                    <td valign="top" width="90%" nowrap align="left">
                        <table border="0" width="100%">
                            <tr><td colspan="7" CLASS="NArialW" ALIGN="CENTER">Direct Margin Report Search</td></tr>
                            <tr><td colspan="7"><img height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width="8"></td></tr>
                            <tr>
                                <td colspan="7" class="NArialL">
                                    <FONT id="errors" color="FF0000"></FONT>
                                    <chiptrack:info styleClass='NArialL'/>
                                    <chiptrack:errors styleClass='NArialL'/>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="15%" class='NArialL'>Cost Code</td>
                                <td width="2%">&nbsp;</td>
                                <td width="20%" class="NArialL">
                                    <nested:select property="searchCostCode" styleClass="txfield" style="width:200px">
                                        <html:option value="0">All Cost Codes</html:option>
                                        <html:options collection="costCodeList" property="value" labelProperty="label"/>
                                    </nested:select>
                                </td>
                                <td width="10%">&nbsp;</td>
                                <td width="15%" class='NArialL'><bean:message key="label.mktgPartNumber"/></td>
                                <td width="5%">&nbsp;</td>
                                <td width="33%" class="NArialL">
                                    <nested:select property="searchProcessstepId" styleClass="txfield" style="width:200px">
                                        <html:option value="0">All Products</html:option>
                                        <html:options collection="partNumberList" property="value" labelProperty="label"/>
                                    </nested:select>
                                </td>
                            </tr>
                            <tr><td colspan="7"><img height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width="8"></td></tr>
                            <tr>
                                <td class='NArialL'>Customer</td>
                                <td>&nbsp;</td>
                                <td class="NArialL">
                                    <nested:select property="searchCustomerId" styleClass="txfield" style="width:200px">
                                        <html:option value="0">All Customers</html:option>
                                        <html:options collection="customerList" property="value" labelProperty="label"/>
                                    </nested:select>
                                </td>
                                <td>&nbsp;</td>
                                <td class='NArialL'>Status</td>
                                <td>&nbsp;</td>
                                <td class="NArialL">
                                    <nested:select property="searchStatus" styleClass="txfield" style="width:200px" onchange="enableDisableDateFields()">
                                        <html:option value="0">All Status</html:option>
                                        <html:options collection="statusList" property="value" labelProperty="label"/>
                                    </nested:select>
                                </td>
                            </tr>
                            <tr><td colspan="7"><img height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width="8"></td></tr>
                            <tr>
                                <td class='NArialL'>DM %</td>
                                <td>&nbsp;</td>
                                <td class="NArialL" colspan="2">
                                    <nested:select property="searchDMPercentageOptr" styleClass="txfield" >
                                        <html:option value="0">Less Than</html:option>
                                        <html:option value="1">Greater Than</html:option>
                                        <html:option value="2">Equal To</html:option>
                                    </nested:select>&nbsp;
                                    <html:text property="searchDMPercentage" styleClass="valuetxfield" size="10" onkeypress="javascript:restrictCharacters(this,7,2)"/>
                                </td>

                                <td class='NArialL'>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td class="NArialL">
                                    &nbsp;
                                </td>
                            </tr>
                            <tr><td colspan="7"><img height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width="8"></td></tr>
                            <tr>
                                <td colspan="7">
                                    <table border="0">
                                        <tr>
                                            <td width="10%" class='NArialL'>Date</td>
                                            <td width="5%">&nbsp;</td>
                                            <td width="10%" class="NArialL">
                                                <html:radio property="searchDateType" value="booking" />Booking
                                            </td>
                                            <td width="10%" class="NArialL">
                                                <html:radio property="searchDateType" value="schedule" />Schedule
                                            </td>
                                            <td width="15%" class="NArialL"><html:radio property="searchDateType" value="shipment" />Ship Date</td>
                                            <td width="15%" class="NArialL">
                                                From Date <br>
                                                <html:text property="searchFromDate" styleClass="txfield" size="12"/>&nbsp;
                                                <a href="javascript:openCalendar(document.directMarginReportForm.searchFromDate)"onmouseover="window.status='Click to Select To Date';return true"onmouseout="window.status='';return true"title="Click here to Select To Date">
                                                    <img border="0" src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=18 width=18></a>
                                            </td>
                                            <td width="5%">&nbsp;</td>
                                            <td width="25%" class="NArialL">
                                                To Date <br>
                                                <html:text property="searchToDate" styleClass="txfield" size="12"/>&nbsp;
                                                <a href="javascript:openCalendar(document.directMarginReportForm.searchToDate)"onmouseover="window.status='Click to Select To Date';return true"onmouseout="window.status='';return true"title="Click here to Select To Date">
                                                    <img border="0" src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=18 width=18></a>
                                            </td>
                                        </tr>
                                        <tr><td colspan="8"><img height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width="8"></td></tr>
                                        <tr>
                                            <td class='NArialL'>Group By</td>
                                            <td>&nbsp;</td>
                                            <td class="NArialL">
                                                <html:radio property="searchGroupBy" value="customer" />Customer
                                            </td>
                                            <td class="NArialL">
                                                <html:radio property="searchGroupBy" value="product" />Part No
                                            </td>
                                            <td class="NArialL" colspan="2">
                                                <html:radio property="searchGroupBy" value="costCode" />Cost Code
                                            </td>
                                            <td class='NArialL' colspan="2">&nbsp;</td>
                                        </tr>
                                        <tr><td colspan="8"><img height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width="8"></td></tr>
                                        <tr><td colspan="8"><img height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width="8"></td></tr>
                                        <tr>
                                            <td class='NArialL'>Sort By</td>
                                            <td>&nbsp;</td>
                                            <td class="NArialL">
                                                <html:radio property="searchSortBy" value="value" />Value
                                            </td>
                                            <td class="NArialL">
                                                <html:radio property="searchSortBy" value="alphabet" />Alphabet
                                            </td>
                                            <td class='NArialL' colspan="4">&nbsp;</td>
                                        </tr>
                                        <tr><td colspan="8"><img height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width="8"></td></tr>
                                        <tr><td colspan="8"><img height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width="8"></td></tr>
                                        <tr>
                                            <td class='NArialL'>Order By</td>
                                            <td>&nbsp;</td>
                                            <td class="NArialL">
                                                <html:radio property="searchOrderBy" value="ascending" />Ascending
                                            </td>
                                            <td class="NArialL">
                                                <html:radio property="searchOrderBy" value="descending" />Descending
                                            </td>
                                            <td class='NArialL' colspan="4">&nbsp;</td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                            <tr><td colspan="7"><img height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width="8"></td></tr>
                            <tr><td colspan="7"><img height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width="8"></td></tr>
                            <tr><td colspan="7"><img height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width="8"></td></tr>
                            <tr><td colspan="7"><img height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width="8"></td></tr>
                            <tr>
                                <td colspan="7" align="center">
                                    <a href="javascript:submitForm();" onMouseOver="window.status='Click to Generate Report';return true" onMouseOut="window.status='';return true" title="Click here to Generate Report"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/submit.gif" width="53" height="17"></a>
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <a href="javascript:resetForm();" onMouseOver="window.status='Click to Reset';return true" onMouseOut="window.status='';return true" title="Click here to Reset">
                                        <img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17">
                                    </a>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </TABLE>
            </html:form>
            <!-- End : Wip Flush -->
            <BR><BR><BR>
        </td>
        <td bgcolor="#ffffff"><img height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></td>
    </tr>
</table>
<!-- Footer starts here -->
<%@include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->
</BODY>
</html>
